﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNG.LIB.Controls;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Web.UI.HtmlControls;
using System.Data;
using System.IO;
public partial class AdminPortal_Controls_TienTe_TienTe_Info : System.Web.UI.UserControl
{
    TblTienTeManager _TblTienTeManager = new TblTienTeManager();
    public int TienID = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try { TienID = Convert.ToInt32(Request.QueryString["id"].Trim()); }
            catch { TienID = 0; }

            if (TienID == 0) //Add cate
            {
                lblTitle.Text = "Thêm tiền tệ";
                Toolbox1.ShowDel = Toolbox1.ShowRefesh = Toolbox1.ShowBack = false;
            }
            else //sua cate
            {
                lblTitle.Text = "Sửa tiền tệ: " + TienID;
                BindData(TienID);
            }
        }
    }


    //load chi tiet san pham
    protected void BindData(int ID)
    {
        TblTienTeEntity _TblTienTeEntity = _TblTienTeManager.SelectOne(ID);
        if (_TblTienTeEntity == null) { lblthongbao.Text = "<img src='../../Images/icon/Icon_warning.gif' alt='Cảnh báo' /> <span style='font-size:11px;color:red;'>  Không có danh mục này </span>"; return; }
        txtID.Text = ID.ToString();
        hidID.Value = ID.ToString();
        txtCode.Text = Server.HtmlDecode(_TblTienTeEntity.Code);
        txtMoTa.Text = Server.HtmlDecode(_TblTienTeEntity.Mota);
        chkStatus.Checked =Convert.ToBoolean( _TblTienTeEntity.TrangThai);
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        BindToData();
        Response.Redirect(SiteMap.CurrentNode.ParentNode.Url);
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(hidID.Value))
        {
            _TblTienTeManager.Delete(Convert.ToInt32(hidID.Value));
        }
        Response.Redirect(SiteMap.CurrentNode.ParentNode.Url);
    }
    protected void btnApply_Click(object sender, EventArgs e)
    {
        if (txtCode.Text == "") { lblthongbao.Text = "<img src='../Images/icon/Icon_warning.gif' alt='Cảnh báo' />  <span style='font-size:11px;color:red;'> Nhập tên mã tiền tệ !</span>"; txtCode.Focus(); return; }
        BindToData();
        Response.Redirect(ResolveUrl("~/AdminPortal/Pages/TienTeEdit.aspx?id=") + hidID.Value);
        //BindData(Convert.ToInt32(hidID.Value));
    }

    private void BindToData()
    {
        TblTienTeEntity _TblTienTeEntity = new TblTienTeEntity();
        if (!string.IsNullOrEmpty(hidID.Value))
            _TblTienTeEntity.Id = Convert.ToInt32(hidID.Value);

        _TblTienTeEntity.LangId = HNG.LIB.Localization.LocalizationUtils.GetCurrentLanguage();
        _TblTienTeEntity.Code = Server.HtmlEncode(txtCode.Text);
        _TblTienTeEntity.Mota = Server.HtmlEncode(txtMoTa.Text);
        _TblTienTeEntity.TrangThai = chkStatus.Checked;

        if (!string.IsNullOrEmpty(hidID.Value))
        {
            _TblTienTeManager.Update(_TblTienTeEntity);
        }
        else
        {
            _TblTienTeManager.Insert(_TblTienTeEntity);
            hidID.Value = _TblTienTeEntity.Id.ToString();
        }

    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect(SiteMap.CurrentNode.ParentNode.Url);
    }
}